#!/usr/bin/python2.4
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Model of a static layer.

A static layer is a reference to a non-modifiable layer.  The layer manifest
is retrieved from the given url.

  Static: Model for a static layer.
"""

__author__ = 'jasonstredwick@google.com (Jason Stredwick)'


# Disable 'Import not at top of file' lint error.
# pylint: disable-msg=C6204
try:
  import auto_import_fixer
except ImportError:
  pass  # This will fail on unittest, ok to pass.

from layer.models.layer_base import Base
from layer.models.layer_base import GetId


class Static(Base):
  """Model for a static layer."""
  # The model's key is the manifest url.
  pass


def Create(url):
  """Create a new Static entry.

  Args:
    url: A string that acts as both the entry's key_name and layer's url.
  Returns:
    Returns a Static object that has been added to the data store.
  """
  layer = Static(key_name=url, url=url, id=GetId())
  layer.put()

  return layer


def Get(url):
  """Lookup a simple layer based on the given url.

  Args:
    url: A string containing the key_name of the layer to retrieve.
  Returns:
    A Static model object or None if the layer does not exist.
  """
  if not url:
    return None

  layer = Static.get_by_key_name(url)
  if not layer:
    return None

  return layer

